// 云函数入口文件
const cloud = require('wx-server-sdk')
const rp = require("request-promise")
cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  var options = {
    uri: 'https://ke.qq.com/cgi-bin/comment_new/course_comment_list',
    qs: {
      cid: '2992323',
      count: '10',
      page: '0',
      r:'0.5811410719279205' // -> uri + '?access_token=xxxxx%20xxxxx'
    },
    headers: {
        'referer':'https://ke.qq.com/course/2992323?taid=10187293061916867'
    },
    json: true // Automatically parses the JSON string in the response
};

let result = await rp(options)
    .then(function (repos) {
       return repos;
    })
    .catch(function (err) {
        // API call failed...
    });


  return {
    event,
    openid: wxContext.OPENID,
    appid: wxContext.APPID,
    unionid: wxContext.UNIONID,
    result
  }
}